package com.xiaobai.waitAndNodify;

import com.xiaobai.util.ThreadUtil;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ThreadWait2 {
   static final Object OBJ = new Object();
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            synchronized (OBJ){
                log.debug("{}running...",Thread.currentThread().getName());
                try {
                    OBJ.wait(1000);
                } catch (InterruptedException e) {
                    log.debug(e.getMessage());
                }
                log.debug("{}running 完成其他代码...",Thread.currentThread().getName());
            }

        },"t1");
//        Thread t2 = new Thread(() -> {
//            synchronized (OBJ){
//                log.debug("{} running ...",Thread.currentThread().getName());
//                try {
//                    //无限制的等待下去
//                    OBJ.wait();
//                    //有时限的等待
//                    //OBJ.wait(1000);
//                } catch (InterruptedException e) {
//                    log.debug(e.getMessage());
//                }
//                log.debug("{}running 完成...",Thread.currentThread().getName());
//            }
//
//        },"t2");
        t1.start();
//        t2.start();
        ThreadUtil.sleep(2);
//        synchronized (OBJ){
//            OBJ.notifyAll();
//        }


    }
}
